package com.cisetech.web.bobocai.houtai;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cisetech.service.CodeService;
import com.cisetech.vo.Page;
import com.cisetech.vo.bobocai.CodeVo;
/*
 * code表操作控制器
 */
@Controller
@RequestMapping(value="/ht/code")
public class CodeController {
	@Autowired
	CodeService codeService;
	
	@RequestMapping(value="/addcode",method=RequestMethod.GET)
	public String addCode(Model model,HttpServletRequest request, HttpServletResponse response){
		return "houtai/addcode";
	}
	
	
	@ResponseBody
	@RequestMapping(value="/addcode",method=RequestMethod.POST)
	public String addCodes(CodeVo codeVo,HttpServletRequest request, HttpServletResponse response){
		int state = codeService.addCode(codeVo);
		return state+"";
	}
	
	@RequestMapping(value="/getlist",method=RequestMethod.GET)
	public String getlist(Model model,HttpServletRequest request, HttpServletResponse response){
		return "houtai/codelist";
	}
	@ResponseBody
	@RequestMapping(value="/getlist",method=RequestMethod.POST)
	public Page<CodeVo> getlists(CodeVo codeVo,HttpServletRequest request, HttpServletResponse response){
		if (codeVo.getProductName()!=null && !"".equals(codeVo.getProductName()) && (codeVo.getProductCode()==null || "".equals(codeVo.getProductCode()))){
			codeVo.setProductCode(codeVo.getProductName());
		}
		Page<CodeVo> page = codeService.getlists(codeVo);
		return page;
	}
	@ResponseBody
	@RequestMapping(value="/delectCode",method=RequestMethod.POST)
	public String delectCode(CodeVo codeVo,HttpServletRequest request, HttpServletResponse response){
		int state = codeService.delectCode(codeVo);
		return state+"";
	}
	@ResponseBody
	@RequestMapping(value="/getlists",method=RequestMethod.POST)
	public List<CodeVo> getlistss(CodeVo codeVo,HttpServletRequest request, HttpServletResponse response){
		
		List<CodeVo> list = codeService.getlistss(codeVo);
		return list;
	}
	@ResponseBody
	@RequestMapping(value="/updateredian",method=RequestMethod.POST)
	public String updateredian(CodeVo codeVo,HttpServletRequest request, HttpServletResponse response){
		try {
			if (codeVo!=null){
				if (codeVo.getRedian()!=null && !"".equals(codeVo.getRedian()) && "1".equals(codeVo.getRedian())){
					codeVo.setRedian("0");
				}else{
					codeVo.setRedian("1");
				}
				int i = codeService.updateByPrimaryKeySelective(codeVo);
				return i + "";
			}
		} catch (Exception e) {
			return "10";
		}
		return "10";
	}
}
